//获取应用实例
const app = getApp();
let util= require('../../../../utils/util2.js');
Page({
  data: {
    // 组件所需的参数
    facilityCode:'',//设备编码
    concent:'', //故障详情
    faultDetails:'',//故障详情
    faultTypeCode:'',//故障类型
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '请填写报修工单', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
  },
  onLoad(opt) {
    let that = this;
    let time = util.formatTime(new Date());
    that.setData({
      faultDetails:time,
      faultTypeCode:opt.faultTypeCode
    })  
    if(that.data.facilityCode==''){
      wx.showModal({
        title:'选择故障设备',
        success(){
          wx.scanCode({
            success(res) {
              console.log(res)
              let facilityCode = res.result;
              that.setData({
                facilityCode: facilityCode
              })
              wx.showModal({
                title: '设备添加成功',
                icon: 'none'
              })
            }
          })
        }
      })
    }
  },
  bindtextChange:function(e){
    let concent = e.detail.value;
    this.setData({concent:concent})
    console.log(this.data.concent)
  },
  bindFormSubmit: function () {
    let that = this;
    console.log(that.data.concent)
    let url = 'https://xiaochengxu.printeasy.top/prod-api/facility/facilityRepairs/login/add?facilityCode='+that.data.facilityCode+'&faultDetails='+that.data.concent+'&faultTypeCode='+that.data.faultTypeCode;
    let data = {};
    app.wxRequest('POST', url, data, (res) => {
      console.log(res)
     if(res.code==200){
      wx.showModal({
        title:'信息已提交',
        scucess(){
          wx.switchTab({
            url: '/pages/index/index'
          });
        }
      })
     }else{
      wx.showModal({
        title:res.msg,
      })
     }
    }, (err) => {
      wx.showModal({
        title:err
      })
      console.log(err.errMsg)
    })
  }
  
})
